const { mongo } = require('../mongodb')
const mongoosePaginate = require('mongoose-paginate-v2')

const User = new mongo.Schema({
  username: {
    type: String,
    required: true,
    trim: true,
    minLength: 1,
    index: true,
    unique: true
  },
  password: {
    type: String,
    required: true,
    trim: true,
    minLength: 1
  },
  role: {
    type: String,
    required: true,
    default: 'user',
    enum: ['user', 'admin']
  },
  initialLevel: {
    type: Number,
    required: true,
    enum: [0, 1, 2, 3],
    default: 0
  },
  learnPurpose: {
    type: Number,
    required: true,
    enum: [0, 1, 2, 3, 4, 5],
    default: 0
  },
  planning: {
    type: Number,
    required: true,
    enum: [0, 1, 2, 3, 4],
    default: 0
  },
  learnStyle: {
    type: Number,
    required: true,
    enum: [0, 1, 2, 3, 4],
    default: 0
  },
  style: Array
})
User.plugin(mongoosePaginate)
// 操作的是model
const user = mongo.model('User', User)

module.exports = user
